package com.jeegit.ecms.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.jeegit.common.core.domain.Ztree;
import com.jeegit.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeegit.ecms.mapper.CmsLinkCategoryMapper;
import com.jeegit.ecms.domain.CmsLinkCategory;
import com.jeegit.ecms.service.ICmsLinkCategoryService;
import com.jeegit.common.core.text.Convert;

/**
 * 网站分类Service业务层处理
 * 
 * @author jeegit
 * @date 2022-06-25
 */
@Service
public class CmsLinkCategoryServiceImpl implements ICmsLinkCategoryService 
{
    @Autowired
    private CmsLinkCategoryMapper cmsLinkCategoryMapper;

    /**
     * 查询网站分类
     * 
     * @param id 网站分类主键
     * @return 网站分类
     */
    @Override
    public CmsLinkCategory selectCmsLinkCategoryById(Long id)
    {
        return cmsLinkCategoryMapper.selectCmsLinkCategoryById(id);
    }

    /**
     * 查询网站分类列表
     * 
     * @param cmsLinkCategory 网站分类
     * @return 网站分类
     */
    @Override
    public List<CmsLinkCategory> selectCmsLinkCategoryList(CmsLinkCategory cmsLinkCategory)
    {
        return cmsLinkCategoryMapper.selectCmsLinkCategoryList(cmsLinkCategory);
    }

    /**
     * 新增网站分类
     * 
     * @param cmsLinkCategory 网站分类
     * @return 结果
     */
    @Override
    public int insertCmsLinkCategory(CmsLinkCategory cmsLinkCategory)
    {
        cmsLinkCategory.setCreateTime(DateUtils.getNowDate());
        return cmsLinkCategoryMapper.insertCmsLinkCategory(cmsLinkCategory);
    }

    /**
     * 修改网站分类
     * 
     * @param cmsLinkCategory 网站分类
     * @return 结果
     */
    @Override
    public int updateCmsLinkCategory(CmsLinkCategory cmsLinkCategory)
    {
        cmsLinkCategory.setUpdateTime(DateUtils.getNowDate());
        return cmsLinkCategoryMapper.updateCmsLinkCategory(cmsLinkCategory);
    }

    /**
     * 批量删除网站分类
     * 
     * @param ids 需要删除的网站分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsLinkCategoryByIds(String ids)
    {
        return cmsLinkCategoryMapper.deleteCmsLinkCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除网站分类信息
     * 
     * @param id 网站分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsLinkCategoryById(Long id)
    {
        return cmsLinkCategoryMapper.deleteCmsLinkCategoryById(id);
    }

    /**
     * 查询网站分类树列表
     * 
     * @return 所有网站分类信息
     */
    @Override
    public List<Ztree> selectCmsLinkCategoryTree()
    {
        List<CmsLinkCategory> cmsLinkCategoryList = cmsLinkCategoryMapper.selectCmsLinkCategoryList(new CmsLinkCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (CmsLinkCategory cmsLinkCategory : cmsLinkCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(cmsLinkCategory.getId());
            ztree.setpId(cmsLinkCategory.getParentId());
            ztree.setName(cmsLinkCategory.getTitle());
            ztree.setTitle(cmsLinkCategory.getTitle());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
